package cn.ivast.recyclerviewtest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.util.Log;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import cn.ivast.recyclerviewtest.adapter.TanTanAdapter;
import cn.ivast.recyclerviewtest.manager.TanTanManager;
import cn.ivast.recyclerviewtest.tantan.CardItemTouchHeplerCallback;
import cn.ivast.recyclerviewtest.tantan.OnSwipeListener;

public class TanTanActivity extends AppCompatActivity {

    private RecyclerView recyclerView;
    private TanTanAdapter adapter;

    private List<String> datas = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tan_tan);
        recyclerView = findViewById(R.id.recyclerView);

        datas.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1543140604386&di=1027e9678e0133cda11263591c31d14a&imgtype=0&src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F54ebececeda0217648263cc944d6cfd413a17cdf2cc6-MGHS0y_fw658");
        datas.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1543140605096&di=49a0a4b3fa1d9af09157f39312c4f58d&imgtype=0&src=http%3A%2F%2Fs16.sinaimg.cn%2Fmw690%2F003OBxcnzy7jF079J7N7f%26690");
        datas.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1543140605094&di=cf2c33d764278c094002326c6690ab2e&imgtype=0&src=http%3A%2F%2Fimgsrc.baidu.com%2Fimgad%2Fpic%2Fitem%2Fc8ea15ce36d3d539ecadcfee3187e950352ab00f.jpg");
        datas.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1543140605092&di=d833a4fdb650c85c82687c72434ea64f&imgtype=0&src=http%3A%2F%2Fimg006.hc360.cn%2Fhb%2FMTQ3NDYwMTg2NTk0MTEzMTkzMjAwMTU%3D.jpg");
        datas.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1543140605092&di=d90d56a3827d5fce315cdba0604eb37b&imgtype=0&src=http%3A%2F%2Fimg66.jc35.com%2F9%2F20160114%2F635883614235589122892.jpg");
        datas.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1543140605091&di=a7700cab6921e3c658d627736c72a230&imgtype=0&src=http%3A%2F%2Fh.hiphotos.baidu.com%2Fzhidao%2Fpic%2Fitem%2F0e2442a7d933c895feee1630d11373f0830200ec.jpg");
        datas.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1543140605088&di=f93329e7e03b0e9b05d2014f4179beca&imgtype=0&src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F4215df5b2fd0e479834179dfeb8b3f0210c55488dd38-3H2Qvj_fw658");


        adapter = new TanTanAdapter(recyclerView);
        adapter.setData(datas);
        recyclerView.setAdapter(adapter);
        CardItemTouchHeplerCallback callback = new CardItemTouchHeplerCallback(recyclerView.getAdapter(), datas);

        callback.setmListener(new OnSwipeListener() {
            @Override
            public void onSwiping(RecyclerView.ViewHolder viewHolder, float ratio, int direction) {
                Toast.makeText(TanTanActivity.this, "ratio:"+ratio+",direction:"+direction, Toast.LENGTH_LONG);
            }

            @Override
            public void onSwiped(RecyclerView.ViewHolder viewHolder, Object o, int direction) {

            }

            @Override
            public void onSwipedClear() {

            }
        });
        ItemTouchHelper touchHelper = new ItemTouchHelper(callback);
        TanTanManager manager = new TanTanManager(recyclerView, touchHelper);
        recyclerView.setLayoutManager(manager);
        touchHelper.attachToRecyclerView(recyclerView);
    }
}
